package com.woyao;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

import java.util.Timer;
import java.util.TimerTask;

public class InputActivity extends AppCompatActivity {
    EditText editText = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        final ActionBar ab = getSupportActionBar();
        ab.setDisplayShowHomeEnabled(true); // show or hide the default home button
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setDisplayShowCustomEnabled(true); // enable overriding the default toolbar layout
        this.setTitle("输入内容");


        Button thebtn = (Button) findViewById(R.id.add_getdecription);

        thebtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("content", editText.getText().toString());
                setResult(666, intent);
                finish();
            }
        });


        TextInputLayout textInputLayout = null;
        Intent intent = getIntent();
        String type =   intent.getStringExtra( "type") ;


        if ( type != null  ) {
            switch (type) {
                case "tag":
                    this.setTitle("关系标签");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("填写关系标签");
                    break;
                case "role":
                    this.setTitle("我的职务");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("填写我的职务");
                    break;
                case "orgaddress":
                    this.setTitle("组织所在地址");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写组织所在地址");
                    break;
                case "orgwebsite":
                    this.setTitle("组织网站地址");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写组织网站地址");
                    break;
                case "orgtitle":
                    this.setTitle("企业或机构名称");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写企业或机构名称");
                    break;
                case "orgdesc":
                    this.setTitle("企业或机构介绍");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_multiple);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写企业或机构介绍");
                    break;
                case "demandtitle":
                    this.setTitle("需求标题");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写需求标题");
                    break;
                case "demanddesc":
                    this.setTitle("需求描述");
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_multiple);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint("请填写需求的具体情况");
                    break;
                case "displayname":
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_single);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint(getString(R.string.displayname));
                    break;
                case "intro":
                    textInputLayout = (TextInputLayout) findViewById(R.id.id_multiple);
                    textInputLayout.setVisibility(View.VISIBLE);
                    textInputLayout.setHint(getString(R.string.intro));
                    break;
                default:

            }
            editText = textInputLayout.getEditText();
            CharSequence tmp = intent.getCharSequenceExtra(  "content");
            editText.setText( tmp );
            editText.setSelection(tmp.length());
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {

                public void run() {
                    InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.showSoftInput(editText, 0);
                }

            }, 500);

        }


    }

    public boolean onOptionsItemSelected(MenuItem item) {
        finish();
        return true;
    }

}
